package hiclib;

import java.sql.*;
import javax.naming.*;
import javax.sql.*;

public class dbconnector {
	Context initContext = null;
	Context envContext = null;
	
	public Connection getConnector(){
		DataSource ds = null;
		Connection conn = null;
		try {
			ds = (DataSource)envContext.lookup("jdbc/HICServer");
		} catch (NamingException e1) {
			e1.printStackTrace();
		}
		
		try{ conn = ds.getConnection();	} catch(Exception e){ return null;}
		return conn;
	}
	
	public dbconnector() {
		try {
			initContext = new InitialContext();
			envContext = (Context) initContext.lookup("java:comp/env");
		} catch (NamingException e) {
			e.printStackTrace();
		} 
	}
	
	public void finalize() {
		try {
			if(envContext != null)	envContext.close();
			envContext = null;
			if(initContext != null)	initContext.close();
			initContext = null;
			
		} catch (NamingException e) {
			e.printStackTrace();
		}		
	}
}
